<?php
class Admin_Model_DbTable_Role extends Zend_Db_Table_Abstract {
	protected $_name = 'role';
	public function addRole($role_name, $create_date, $description, $status) {
		$data = array (
				'ROLE_NAME' => $role_name,
				'CREATE_DATE' => $create_date,
				'DESCRIPTION' => $description,
				'STATUS' => $status 
		);
		return $this->insert ( $data );
	}
	public function updateRole($id, $role_name, $create_date, $description, $status) {
		$data = array (
				'ROLE_NAME' => $role_name,
				'CREATE_DATE' => $create_date,
				'DESCRIPTION' => $description,
				'STATUS' => $status 
		);
		return $this->update ( $data, "ID = $id" );
	}
	public function updateStatus($id, $status) {
		$data = array (
				'STATUS' => $status 
		);
		return $this->update ( $data, "ID = $id" );
	}
	public function activeRole($id) {
		$lv = $this->fetchRow ( "ID = $id" );
		if ($lv ["STATUS"] == 1) {
			$this->update ( array (
					"STATUS" => 0 
			), "ID = $id" );
		} else {
			$this->update ( array (
					"STATUS" => 1 
			), "ID = $id" );
		}
	}
	public function removeRole($id) {
		return $this->delete ( "ID = $id" );
	}
	public function getAllRole() {
		return $this->fetchAll ()->toArray ();
	}
	public function getRoleById($id) {
		return $this->fetchRow ( "ID = $id AND STATUS = 1" )->toArray ();
	}
	public function getRoleByRoleName($role_name) {
		return $this->fetchRow ( "ROLE_NAME = '$role_name'" )->toArray ();
	}
}


